package __Goquery

import (
	"fmt"
	"github.com/PuerkitoBio/goquery"
	"log"
)

//goquery 进行html页面元素的提取，类似于jQuery
//官方文档https://github.com/PuerkitoBio/goquery
//go get github.com/PuerkitoBio/goquery

func main() {
	url := "https://gorm.io/zh_CN/docs/"
	//Document表示要爬取的文档
	dom, err := goquery.NewDocument(url)
	if err != nil {
		log.Fatalln("访问失败", err)
	}
	dom.Find(".sidebar-link").Each(func(i int, s *goquery.Selection) {
		href, _ := s.Attr("href")
		text := s.Text()
		fmt.Println(i, href, text)
	})
}
